package cn.iocoder.yudao.module.data.controller.admin.ds;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.data.controller.admin.dscategory.vo.DsPreSqlReqVO;
import cn.iocoder.yudao.module.data.service.ds.DsServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author gukun
 */
@Tag(name = "管理后台 - 数据源")
@RestController
@RequestMapping("/data/ds")
@Validated
public class DsController {
    @Resource
    private DsServiceImpl dsService;

    @PostMapping("/previewSql")
    @Operation(summary = "预览数据结果")
    public CommonResult<Map<String,Object>> previewSql(@Valid @RequestBody DsPreSqlReqVO dsPreSqlReqVO) {
        Map<String, Object> stringObjectMap = dsService.executeSql(dsPreSqlReqVO.getSql(), dsPreSqlReqVO.getDsId());
        return CommonResult.success(stringObjectMap);
    }

//    @PostMapping("/saveDs")
//    @Operation(summary = "预览数据结果")
//    public CommonResult<Map<String,Object>> previewSql(DsPreSqlReqVO dsPreSqlReqVO) {
//        Map<String, Object> stringObjectMap = dsService.executeSql(dsPreSqlReqVO.getSql(), dsPreSqlReqVO.getDbInfoDto());
//        return CommonResult.success(stringObjectMap);
//    }
}
